package io.renren.roomManager.service.impl;

import cn.lingyueblog.common.utils.PageUtils;
import cn.lingyueblog.common.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.roomManager.dao.RoomsDao;
import io.renren.roomManager.entity.RoomsEntity;
import io.renren.roomManager.service.RoomsService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;


@Service("roomsService")
public class RoomsServiceImpl extends ServiceImpl<RoomsDao, RoomsEntity> implements RoomsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        QueryWrapper<RoomsEntity> wrapper = new QueryWrapper<RoomsEntity>();
        if (!key.isEmpty()){
            wrapper.like("number",key);
        }
        IPage<RoomsEntity> page = this.page(
                new Query<RoomsEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void roomSave(RoomsEntity rooms) {
        rooms.setCreatedat(new Date());
        rooms.setUpdatedat(new Date());
        rooms.setDeletedat(null);
        save(rooms);
    }

}